﻿using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Read.API.Appliaction.Commends.zmc.Warehou;
using B.S.Sterilizationcenter.Read.API.Dto;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Read.API.Appliaction.CommandHandlers.zmc.Warehou
{
    public class CleaningrecordsCommendHandlers : IRequestHandler<CleaningrecordsCommends, ApiResult<List<CleaningorderWarehousDto>>>
    {


        private readonly ISqlSugarClient db;

        public CleaningrecordsCommendHandlers(ISqlSugarClient db)
        {
            this.db = db;
        }


        /// <summary>
        /// 获取清洗记录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<List<CleaningorderWarehousDto>>> Handle(CleaningrecordsCommends request, CancellationToken cancellationToken)
        {
            try
            {

                ApiResult<List<CleaningorderWarehousDto>> result = new ApiResult<List<CleaningorderWarehousDto>>();
                result.Code = ApiEnums.查询成功;
                result.Msg= "查询成功";
                var list = db.Queryable<Cleaningorder,Warehous>((a,b)=>a.WarehousId==b.WarehousId ).Select((a,b)=>new CleaningorderWarehousDto
                {
                    CleaningOrderId = a.CleaningOrderId,
                    WarehousId = b.WarehousId,
                    StuffId = a.StuffId,
                    DeviceType = a.DeviceType,
                    ProgramType = a.ProgramType,
                    Duration = a.Duration,
                    Result= a.Result,
                    Temperature = a.Temperature,
                    CreateTime = a.CreateTime,
                    Status=b.Status,

                }).ToList();
                result.Data = list;
                return result;

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
